﻿using System;
using System.Collections.Generic;

namespace Flagwind.Services
{
    public class CommandCompletionContext : CommandExecutorContext
    {
        #region 成员字段

        private object _result;
        private Exception _exception;

        #endregion

        #region 构造方法

        public CommandCompletionContext(ICommandExecutor executor, CommandExpression expression, object parameter, object result, Exception exception = null) : base(executor, expression, parameter)
        {
            _result = result;
            _exception = exception;
        }

        #endregion

        #region 公共属性

        public object Result
        {
            get
            {
                return _result;
            }
            set
            {
                _result = value;
            }
        }

        public Exception Exception
        {
            get
            {
                return _exception;
            }
            set
            {
                _exception = value;
            }
        }

        #endregion

        #region 静态方法

        public static CommandCompletionContext Create(CommandExecutorContext context, object result, Exception exception = null)
        {
            if(context == null)
                throw new ArgumentNullException(nameof(context));

            return new CommandCompletionContext(context.Executor, context.Expression, context.Parameter, result, exception);
        }

        #endregion
    }
}